using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The SchoolMajorTableManager class is responsible for managing BO.SchoolMajorTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class SchoolMajorTableManager
    {

        #region "Public Methods"

        ///// <summary>
        ///// Gets a list with all SchoolMajorTable objects in the database.
        ///// </summary>
        ///// <returns>A list with all SchoolMajorTable from the database when the database contains any, or null otherwise.</returns>
        //[DataObjectMethod(DataObjectMethodType.Select, true)]
        //public static SchoolMajorTableList GetList()
        //{
        //    return SchoolMajorTableDB.GetList();
        //}

        /// <summary>
        /// Custom
        /// Gets a list with all SchoolMajorTable objects in the database.
        /// </summary>
        /// <param name="schoolKey">The SchoolKey of the SchoolMajorTable in the database.</param>
        /// <returns>A list with all SchoolMajorTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static SchoolMajorTableList GetList(int SchoolKey)
        {
            return SchoolMajorTableDB.GetList(SchoolKey);
        }

        /// <summary>
        /// Gets a single SchoolMajorTable from the database without its data.
        /// </summary>
        /// <param name="schoolMajorKey">The SchoolMajorKey of the SchoolMajorTable in the database.</param>
        /// <returns>A SchoolMajorTable object when the SchoolMajorKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static SchoolMajorTable GetItem(int schoolMajorKey)
        {
            return GetItem(schoolMajorKey, false);
        }

        /// <summary>
        /// Gets a single SchoolMajorTable from the database.
        /// </summary>
        /// <param name="schoolMajorKey">The SchoolMajorKey of the SchoolMajorTable in the database.</param>
        /// <param name="getSchoolMajorTableRecords">Determines whether to load all associated SchoolMajorTable records as well.</param>
        /// <returns>
        /// A SchoolMajorTable object when the SchoolMajorKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static SchoolMajorTable GetItem(int schoolMajorKey, bool getSchoolMajorTableRecords)
        {
            SchoolMajorTable mySchoolMajorTable = SchoolMajorTableDB.GetItem(schoolMajorKey);
            //if (mySchoolMajorTable != null && getSchoolMajorTableRecords)
            //{
            //    mySchoolMajorTable.standardLevelTables = StandardLevelTableDB.GetListBySchoolMajorKey(schoolMajorKey);
            //}
            return mySchoolMajorTable;
        }

        /// <summary>
        /// Saves a SchoolMajorTable in the database.
        /// </summary>
        /// <param name="mySchoolMajorTable">The SchoolMajorTable instance to save.</param>
        /// <returns>The new SchoolMajorKey if the SchoolMajorTable is new in the database or the existing SchoolMajorKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(SchoolMajorTable mySchoolMajorTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int schoolMajorTableSchoolMajorKey = SchoolMajorTableDB.Save(mySchoolMajorTable);
                //foreach (StandardLevelTable myStandardLevelTable in mySchoolMajorTable.standardLevelTables)
                //{
                //    myStandardLevelTable.SchoolMajorKey = schoolMajorTableSchoolMajorKey;
                //    StandardLevelTableDB.Save(myStandardLevelTable);
                //}

                //  Assign the SchoolMajorTable its new (or existing SchoolMajorKey).
                mySchoolMajorTable.SchoolMajorKey = schoolMajorTableSchoolMajorKey;

                myTransactionScope.Complete();

                return schoolMajorTableSchoolMajorKey;
            }
        }

        /// <summary>
        /// Deletes a SchoolMajorTable from the database.
        /// </summary>
        /// <param name="mySchoolMajorTable">The SchoolMajorTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(SchoolMajorTable mySchoolMajorTable)
        {
            return SchoolMajorTableDB.Delete(mySchoolMajorTable.SchoolMajorKey);
        }

        /// <summary>
        /// Custom
        /// Deletes a SchoolMajorTable from the database.
        /// </summary>
        /// <param name="SchoolMajorKey">The SchoolMajorTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(int SchoolMajorKey)
        {
            return SchoolMajorTableDB.Delete(SchoolMajorKey);
        }

        #endregion

    }

}
